package chapter2.No2_2_synchronized同步语句块.i静态同步方法与synchronized_class代码块.demo2;

/**
 * Created by Administrator on 2016/11/12.
 */
public class ServiceClass {

    public synchronized static void methodA() {
        try {
            System.out.println("线程：" + Thread.currentThread().getName() + " 进入静态同步方法A");
            Thread.sleep(500);
            System.out.println("线程：" + Thread.currentThread().getName() + " 退出静态同步方法A");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized static void methodB() {
        try {
            System.out.println("线程：" + Thread.currentThread().getName() + " 进入静态同步方法B");
            Thread.sleep(500);
            System.out.println("线程：" + Thread.currentThread().getName() + " 退出静态同步方法B");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized void methodC() {
        System.out.println("线程：" + Thread.currentThread().getName() + " 进入同步方法C(非静态)");
        System.out.println("线程：" + Thread.currentThread().getName() + " 退出同步方法C(非静态)");
    }
}
